#include <Arduino.h>
#include <ESP8266WiFi.h>

const char *ssid = "dayuan";
const char *pswd = "19900625";
const char *devivename = "esp8266-dev";

IPAddress staticIP(192, 168, 3, 221); // 静态IP
IPAddress gateway(192, 168, 3, 1);    // 网关
IPAddress subnet(255, 255, 255, 0);   // 子网掩码
IPAddress dns(8, 8, 8, 8);            // dns服务器

void setup()
{
  Serial.begin(115200);
  WiFi.hostname(devivename);
  WiFi.config(staticIP, gateway, subnet, dns);
  // 设置wifi模式
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pswd);

  Serial.printf("开始连接wifi：%s\n", ssid);

  unsigned long startTime = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000)
  { // wifi连接中
    delay(500);
    Serial.print(".");
  }

  if (WiFi.status() == WL_CONNECTED) // wifi连接成功
  {
    Serial.println("\nWiFi  连接成功！");
    Serial.print("IP:");
    Serial.println(WiFi.localIP());
  }
}

void loop()
{
  delay(1000);
}